package main;

import java.util.Iterator;
import java.util.List;

import hibernate.daos.HabitacionDao;
import hibernate.pojos.Users;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import org.springframework.core.io.FileSystemResource;

import servicios.ServicioUsuarios;

public class EjecucionAnotaciones {

	

	public static void main(String args[]) {
		
		String path = "D:/workspaceSpringDay/springday-orm-hibernate/src/config/context.xml";
		XmlBeanFactory factory = new XmlBeanFactory(
				new FileSystemResource(path));
		
		ServicioUsuarios serv = (ServicioUsuarios) factory
				.getBean("usuarioService");
		
		//guardando un usuario
		Users usr = new Users();
		usr.setUsername("33452268");
		usr.setNombre("Spring");
		usr.setApePaterno("Day2");
		usr.setApeMaterno("2010");
		usr.setEnabled(1);
		
		serv.guardar(usr);
		
		List listaUsuarios =serv.listarUsuarios();
		
		Iterator i = listaUsuarios.iterator();
		while(i.hasNext()){
			Users u = (Users) i.next();
			System.out.println(u.getUsername()+" - "+u.getNombre());
		}
		
	}

}
